
package com.yu.interceptor;

import javax.servlet.http.HttpSession;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.yu.model.User;

/**
 * 后台
 * @author chengjun
 *
 */
public class LoginInterceptor implements Interceptor {

    public void intercept(Invocation inv) {
        Controller controller = inv.getController();
        HttpSession session = controller.getSession();
        controller.setAttr("title", "东家帮管理后台");
        if (session.getAttribute("admin") != null){
        	User user = (User) session.getAttribute("admin");
        	controller.setAttr("admin", user);
        	controller.setAttr("type", user.getInt("type"));
        	inv.invoke();
        } else {
        	String message = "请先登录再进行操作！";
            controller.setAttr("message", message);
            String redirectionUrl = controller.getRequest().getContextPath() + "/";
            controller.setAttr("redirectionUrl", redirectionUrl);
            controller.render("/WEB-INF/view/admin/login.html");
        }
    }
}
